package com.woniuxy.micromemberserver.mapper;

import com.github.pagehelper.PageInfo;
import com.woniuxy.micromemberserver.bean.MemberBean;
import com.woniuxy.micromemberserver.bean.PageRequest;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 会员持久层接口
 * @Author hz
 */
@Service
public interface MemberMapper {

    /**
     * 新增会员
     * @param memberBean
     * @return
     */
    @Options(
            useGeneratedKeys = true,
            keyProperty = "m.id"
    )
    @Insert(
        "insert into t_member_info"+
        "(card_number, member_name, member_phone, fk_level_id, fk_store_id, gender, birthday, mail, exp, integral, balance, monetary, consumption_date, consumption_count, registered_source, registered_code, personal_code, del_status)"+
        "values (#{m.cardNumber}, #{m.memberName}, #{m.memberPhone}, #{m.memberTypeBean.id}, #{m.storeBean.id}, #{m.gender}, #{m.birthday}, #{m.mail}, #{m.exp}, #{m.integral}, #{m.balance}, #{m.monetary}, #{m.consumptionDate}, #{m.consumptionCount}, #{m.registeredSource}, #{m.registeredCode}, #{m.personalCode}, #{m.delStatus})"
    )
    int saveMember(@Param("m") MemberBean memberBean);

    /**
     * 条件分页查询
     * @param request 分页请求
     * @param memberBean 会员实体
     * @return
     */
    List<MemberBean> findAllByParams(@Param("p") PageRequest request, @Param("m") MemberBean memberBean);

    /**
     * 修改会员（或删除：仅修改删除标记）
     * @param memberBean
     * @return
     */
    int updateMember(@Param("m") MemberBean memberBean);

}
